/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.winni.Controller;


import java.io.IOException;
import java.io.Writer;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class LoginServlet extends HttpServlet {
	@Override
        protected void service(HttpServletRequest req,HttpServletResponse res)
        throws IOException,ServletException{
		
//System.out.println("**Service() called**");
////collecting the CLIENT DATA
//String username=req.getParameter("username");
//String password=req.getParameter("password");
////VALIDATING THE DATA
//String msg="";
//if(username==null||username.length()==0){
//	msg="<h1>Provide username and password<h1>";
//}else if(password==null||password.length()==0){
//	msg="<h1>provide username and password</h1>";
//}else{
//	//VERIFYING THE DATA USING JDBC code
//	boolean valid=username.equals(password);
//	if(valid){
//	msg="<h1> Hi "+ username +"<br/> This is your home page</h1>";
//	}else{
//		msg="<h1>INVALID LOGIN DETAILS</h1>";
//	}
//}
//res.setContentType("text/html");
//Writer out=res.getWriter();
////res.sendRedirect("/WEB-INF/JSP/addandview.jsp");
////WRITING THE RESPONSE MESSAGE
//out.write(msg);
        try{    
            String uname=req.getParameter("username");
            String password=req.getParameter("password");
            if(uname.equals("admin") && password.equals("1234")){
               
                RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/JSP/addandview.jsp");
                rd.forward(req, res);
            }
        }catch(Exception e){
            e.printStackTrace();
       }
                 System.out.println("inside loginServlet");
                 RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/JSP/login.jsp");
                 rd.forward(req, res);
            
    

res.sendRedirect("./JSP/login.jsp");



	}
}
    